package cn.com.taiji.oospub.wechat.service.impl;

import cn.com.taiji.oospub.wechat.entity.MemberBaseInfo;
import cn.com.taiji.oospub.wechat.mapper.MemberBaseInfoMapper;
import cn.com.taiji.oospub.wechat.service.IMemberBaseInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.dreamyoung.mprelation.AutoMapper;
import com.github.dreamyoung.mprelation.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author yzd
 * @since 2020-10-28
 */
@Service
public class MemberBaseInfoServiceImpl extends ServiceImpl<MemberBaseInfoMapper, MemberBaseInfo> implements IMemberBaseInfoService {


    @Autowired
    private MemberBaseInfoMapper memberBaseInfoMapper;
    @Autowired
    private AutoMapper autoMapper;


    @Override
    public MemberBaseInfo findByProperty(String columnName, String value) {
        QueryWrapper<MemberBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(columnName, value);
        List<MemberBaseInfo> memberBaseInfos = memberBaseInfoMapper.selectList(queryWrapper);
        if (memberBaseInfos.size() > 0) {
            return autoMapper.mapperEntity(memberBaseInfos.get(0));
        }
        return null;
    }

    @Override
    public MemberBaseInfo findByPhone(String mobile) {
        QueryWrapper<MemberBaseInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("Mobile", mobile);
        List<MemberBaseInfo> memberBaseInfos = memberBaseInfoMapper.selectList(queryWrapper);
        if (memberBaseInfos.size() > 0) {
            return memberBaseInfos.get(0);
        } else {
            return null;
        }
    }

    @Override
    public MemberBaseInfo findById(String id) {
        MemberBaseInfo memberBaseInfo = memberBaseInfoMapper.selectById(id);
        autoMapper.mapper(memberBaseInfo);
        return memberBaseInfo;
    }

    @Override
    public MemberBaseInfo getByLoginName(String loginName) {
        return this.findByProperty("Login_Name", loginName);
    }
}
